package com.kaifamiao.statements;

import java.util.Scanner;

public class Cat {
    public static void main(String[] args) {
        // 初始化
        int counter = 10;
        // 条件
        while( counter > 0 ) { // 循环体开始
            System.out.printf("%d\t", counter);
            // 迭代部分
            counter--;
        } // 循环体结束
        System.out.println();

        System.out.println( "- ".repeat( 20 ) );

        // 用 while 循环求 1 到 100 所有自然数之和
        int sum = 0;
        int n = 1;
        while( n <= 100 ){
            sum += n;
            n++;
        }
        System.out.println( sum );

        System.out.println( "- ".repeat( 20 ) );

        final int x = 9527;
        int temp = x ;
        while( temp > 0 ) {
            int yu = temp % 10; // 整除求余数
            temp = temp / 10; // 整除求商
            // System.out.println( "余数: " + yu + ", 商: " + temp );
            System.out.printf("%d, " , yu);
        }
        System.out.println();

        System.out.println( "- ".repeat( 20 ) );

        Scanner s = new Scanner( System.in );

        System.out.println("请输入你的年龄");
        int age = s.nextInt();

        while( age < 0 || age > 150 ) {
            System.out.println( "你输入的年龄不符合正常人类的寿命范围，请重新输入" );
            age = s.nextInt();
        }

        System.out.println( "你输入的年龄是: " + age );

        s.close();

    }
}
